package cn.swust.score.controller; 

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import cn.swust.score.pojo.Rater; 

public class BaseController {
 	public int getRateId(){
		int id = -1;
		 Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
		if (authentication != null) {
			Rater rater = ((Rater) authentication.getPrincipal());
			id = rater.getId();
		}
	return id;	
	//	  return 1;
	}
	
	
	public String getRateSchool(){
		String school="";
		 Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
		if (authentication != null) {
			Rater rater = ((Rater) authentication.getPrincipal());
			school = rater.getSchool();
		}
		return school;	
		//return "川大";
	}
	
	public void setRefreshId(HttpServletRequest request, int i)
	{
		HttpSession session = request.getSession();
		session.setAttribute("REFRESH_COUNT", 1); 
	}
	
	public int getRefreshId(HttpServletRequest request){
		HttpSession session = request.getSession();
		Integer refresh = (Integer)session.getAttribute("REFRESH_COUNT");
		if (refresh == null)
			return 0;
		else
			return refresh; 
	} 
}
